package models;

import android.app.Application;

/**
 * This is a global class that provides functionality that is commonly used in all Android Activities
 * in this application.
 * @author Nikhil Karkarey and Abdelelah Salama
 *
 */
public class Utility extends Application {
	
	// time constants
	public static final int MAX_TRAVEL_TIME = 1440; // 1440 min = 24 hours
	public static final int MAX_TASK_DURATION = 1440; // 1440 min = 24 hours
	
	// Bundle keys
	public static final String BUNDLE_NEW_TASK_FLAG = "createNewTask";
	public static final String BUNDLE_TASK_ID = "taskId";
	public static final String BUNDLE_TASK_TITLE = "taskTitle";
	public static final String BUNDLE_TASK_START_TIME = "startTime";
	public static final String BUNDLE_TASK_END_TIME = "endTime";
	public static final String BUNDLE_TASK_DURATION = "taskDuration";
	public static final String BUNDLE_TASK_TRAVEL_TIME = "taskTravelTime";
	public static final String BUNDLE_TASK_PRIORITY = "taskPriority";
	
	// Activity result codes
	public static final int RETURN_CODE_CANCEL = 0;
	public static final int RETURN_CODE_NEW_TASK_INFO = 1;
	public static final int RETURN_CODE_EDIT_TASK_INFO = 2;
	public static final int RETURN_CODE_START_END_TIME_INFO = 3;
	public static final int RETURN_CODE_SAVE_PREVIEW = 4;
	
	private static boolean allTasksIncluded;
	
	// returns String associated with 
	public static String getPriorityString(int priority) {
		switch(priority) {
			case 0: return "Low";
			case 1: return "Medium";
			case 2: return "High";
			case 3: return "Do or Die!";
			default: throw new IllegalArgumentException("invalid priority number");
		}
	}
	
	public static int getPriorityInt(String priority) {
		if(priority.trim().equalsIgnoreCase("Low")) {
			return 0;
		}
		if(priority.trim().equalsIgnoreCase("Medium")) {
			return 1;
		}
		if(priority.trim().equalsIgnoreCase("High")) {
			return 2;
		}
		if(priority.trim().equalsIgnoreCase("Do or Die!")) {
			return 3;
		}
		
		return 0;
	}
	
	public static void setAllTasksIncludedFlag(boolean f) {
		allTasksIncluded = f;
	}
	public static boolean getAllTasksIncludedFlag() {
		return allTasksIncluded;
	}
}
